package com.hippo.core.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hippo.core.pojo.vo.MessageVO;

/**
 * @ClassName MessageUtils
 * @Description TODO websocket消息封装工具类
 * @Author tangxl
 * @create 2023-04-21 14:10
 **/
public class MessageUtils {
    /**
     * 消息封装
     */
    public static String getMessage(Boolean isSystem, Integer fromUserId, String message) {
        try {
            MessageVO messageVO = new MessageVO();
            messageVO.setSystem(isSystem);
            messageVO.setMessage(message);
            if(isSystem){
                messageVO.setFromUserId(0);
            }
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsString(messageVO);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
